<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['hdps']=$basic['hdps'];
if($_RQ['op']=='main'){
	set_html('title','小孩列表');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$post=get_postdata();
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	//排序老师
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$return['status']=0;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	$list=pdo_getslice('jy_edu_body',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$sum=0;
	if($list){
		$sum=count($list);
		foreach($list as &$item){		
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['lessontitle']=pdo_getcolumn('jy_edu_lesson',array('id'=>$item['lessonid']),'title');
			$item['classttile']=pdo_getcolumn('jy_edu_class',array('id'=>$item['classid']),'title');
			$item['xuestatus']=$item['agetime']>TIMESTAMP?:false;
			if($item['isxue']){
				$item['lessonlast']=$this->model('lesson')->get_lessonlast($item);
			}else{
				$item['lessonlast']='该小孩还没报名任何班级';
			}
		}
	}
	$return['list']=$list;
	$return['sum']=$sum;
	set_html('title','小孩列表');
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	$return['item']=pdo_get('jy_edu_body',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	if($return['item']['classid']){
			$return['item']['class']=$this->get('class',array('id'=>$return['item']['classid']));
			$return['item']['classgroup']=$this->get('class_group',array('id'=>$return['item']['class']['group_id']));
			$return['item']['classworker']=$this->get('worker',array('id'=>$return['item']['class']['workerid']));
		}
		if($return['item']['lesson_id']){
			$return['item']['lesson']=$this->get('lesson',array('id'=>$return['item']['lesson_id']));
			$return['item']['lessonworker']=$this->get('worker',array('id'=>$return['item']['lesson']['workerid']));
			$return['item']['class']=$this->get('class',array('id'=>$return['item']['lesson']['classid']));
			$return['item']['classgroup']=$this->get('class_group',array('id'=>$return['item']['class']['group_id']));
			$return['item']['classworker']=$this->get('worker',array('id'=>$return['item']['class']['workerid']));
		}
		if($return['item']['bodyid']){
			$return['item']['body']=$this->get('body',array('id'=>$return['item']['bodyid']));
		}
		if($return['item']['storeid']){
			$return['item']['store']=$this->get('store',array('id'=>$return['item']['storeid']));
			$return['item']['store']['pcd']=json_decode($return['item']['store']['pcd'],true);
		}
		$return['item']['statustitle']=$this->order_status[$return['item']['status']];
		$return['item']['createtime']=date('Y-m-d H:i:s',$return['item']['createtime']);
	set_html('title','小孩详情');
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_edu_body',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		$item=array();
	}
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['name']){
		exi('请填写小孩姓名','error');
	}
	$data =array(
		'name'=>$postdata['name'],
		'avatar'=>$postdata['avatar'],
		'agetime'=>intval(strtotime($postdata['agetime'])),
		'sex'=>intval($postdata['sex']),
	);
	if($postdata['id']){
		pdo_update('jy_edu_body',$data,array('id'=>$postdata['id'],'uniacid'=>$_SESSION['uniacid']));
		exi('修改成功','','jy_edu/body_list/main/');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['mid']=$_SESSION['uid'];
		$data['createtime']=time();
		pdo_insert('jy_edu_body',$data);
		exi('添加成功','','jy_edu/body_list/main/');
	}
}
